<!DOCTYPE html>
<html>
<head>
<#include "../common/common.ftl">
<#include "../common/datatables.ftl">
<#include "../common/jqplot.ftl">
	<title><@spring.message "navigator.demand"/></title>
	<link href="${req.getContextPath()}/plugins/datepicker/css/datepicker.css" rel="stylesheet">
	<style>
		td.today {
			background: url('${req.getContextPath()}/img/icon_today.png') no-repeat left top;
		}

		td.yesterday {
			background: url('${req.getContextPath()}/img/icon_yesterday.png') no-repeat left top;
		}

		.popover {
			width: auto;
			min-width: 300px;
			max-width: 600px;
			max-height: 500px;
			overflow-y: scroll;
		}
		.datepicker {
			z-index:1151;
		}
		.select-item {
			width: 60px;
		}
		.popover-content {
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}

		div.small-chart {
			border: 1px solid #878988;
			height: 150px;
			min-width: 290px;
		}

		td.no-padding {
			padding: 0;
		}

		table.jqplot-table-legend {
			left: 32px !important;
			top: 7px  !important;
		}

		td.jqplot-table-legend {
			padding-bottom: 0;
		}

        .img-unit {
            background-image: url('${req.getContextPath()}/img/bg_perftest_banner_en.png?${nGrinderVersion}');
            height: 110px;
            padding: 0;
            margin-top: 0px;
        }

		th.small-border {
			padding-left:3px;
			padding-right:3px;
		}

	</style>
</head>

<body>
	<div id="wrap">
		<#include "../common/navigator.ftl">

		<div class="container">
			<div style="margin: 10px 0;">
				<form id="test_list_form" name="test_list_form" class="well form-inline search-bar" style="margin-top:0;margin-bottom:0;height:30px;" 
					action="${req.getContextPath()}/demand/list" method="POST">
					<div class="left-float">
					</div>

					<div class="right-float">
					
						<a class="btn btn-primary" href="${req.getContextPath()}/demand/new" id="create_btn">
							<i class="icon-file icon-white"></i>
							新建需求
						</a>
						<a class="pointer-cursor btn btn-danger" id="delete_btn">
							<i class="icon-remove icon-white"></i>
							删除需求
						</a>
					</div>

					<input type="hidden" id="page_number" name="page.page" value="${page.pageNumber + 1}">
					<input type="hidden" id="page_size" name="page.size" value="${page.pageSize}">
				</form>


				<@security.authorize ifAnyGranted="A, S">
					<#assign isAdmin = true />
				</@security.authorize>

				<table class="table table-striped table-bordered ellipsis" id="test_table" style="width:940px">
					<colgroup>
						<col width="30"> 
						<col>
						<col>
						<col>
						<col>
						<col>
						<col>
						<col>
						<col>
						<col width="60">
					</colgroup>
					<thead>
						<tr id="head_tr_id">
							<th class="nothing"><input id="chkboxAll" type="checkbox" class="checkbox" value=""></th>
							<th>项目</th>
							<th>版本</th>
							<th>测试目的</th>
							<th>提交时间</th>
							<th>需求提交人</th>
							<th>脚本目录</th>
							<th>场景</th>
							<th>测试结果</th>
							<th class="nothing"><@spring.message "common.label.actions"/></th>
						</tr>
					</thead>
					<tbody>
						<#assign testList = testListPage.content/>						
						<@list list_items=testList others="table_list"; test, test_index>
						<tr>
							<td class="center">
								<input id="check_${test.id}" type="checkbox" class="checkbox" value="${test.id}">								
							</td>
							<td class="ellipsis">
								<a href="${req.getContextPath()}/demand/${test.id}">${(test.projectNameCn)!}</a>
							</td>
							<td class="ellipsis">${test.ver}</td>
							<td class="ellipsis">${test.testPrupose}</td>
							<td class="ellipsis">${test.date}</td>
							<td class="ellipsis">${test.requireman}</td>
							<td class="ellipsis">
								<a href="${req.getContextPath()}/script/list/${(test.projectName)!}_${test.id}">${(test.projectName)!}</a>
							</td>
							<td class="ellipsis" style="text-align: center;">
								<#if test.hasTestData gt 0>
								<a href="${req.getContextPath()}/perftest/list?demandId=${test.id}"><i title="创建测试" class="icon-plus"></i> 创建测试</a>
								<#else>
								<a href="${req.getContextPath()}/perftest/new?demandId=${test.id}"><i title="创建测试" class="icon-plus"></i> 创建测试</a>
								</#if>
							</td>
							<td class="ellipsis" style="text-align: center;">
								<a href="${req.getContextPath()}/demand/report/${test.id}"><i title="测试结果" class="icon-tasks"></i> 测试结果</a>
							</td>
							<td class="center">
								<i title="删除" id="delete_${test.id}"
								   class="icon-remove test-remove pointer-cursor" sid="${test.id}"></i>

							</td>
						</tr>
						</@list>
					</tbody>
				</table>
				<#if testList?has_content>
					<#include "../common/paging.ftl">
					<@paging  testListPage.totalElements testListPage.number+1 testListPage.size 10 ""/>
				<script type="text/javascript">
					function doSubmit(page) {
						getList(page);
					}
				</script>
				</#if>
			</div>
		</div>



	</div>
	<#include "../common/copyright.ftl">

    <script>
		$(document).ready(function(){
			$("#nav_demand").addClass("active");

			enableCheckboxSelectAll("test_table");

			$("i.test-remove").click(function () {
				var id = $(this).attr("sid");
				bootbox.confirm("确定要删除该需求吗？", "<@spring.message "common.button.cancel"/>", "<@spring.message "common.button.ok"/>", function (result) {
					if (result) {
						deleteTests(id);
						setTimeout(location.reload, 1000);
					}
				});
			});

			$("#delete_btn").click(function () {
				var list = $("td input:checked");
				if (list.length == 0) {
					bootbox.alert("没有选择项", "<@spring.message "common.button.ok"/>");
					return;
				}

				bootbox.confirm("确定要删除所选需求吗？", "<@spring.message "common.button.cancel"/>", "<@spring.message "common.button.ok"/>", function (result) {
					if (result) {
						var ids = list.map(function () {
							return $(this).val();
						}).get().join(",");

						deleteTests(ids);
					}
				});
			});
		});

		function deleteTests(ids) {
			var ajaxObj = new AjaxObj("/demand/api?ids="+ ids,
					"删除成功",
					"删除失败");
			ajaxObj.type = "DELETE";
			ajaxObj.success = function () {
				setTimeout(function () {
					getList(1);
				}, 500);
			};
			ajaxObj.call();
		}

		function getList(page) {
			$("#page_number").val(page);
			document.forms.test_list_form.submit();
		}
	</script>
</body>
</html>

